package com.mmall.controller.backend;

import com.mmall.common.Const;
import com.mmall.common.ResponseCode;
import com.mmall.common.ServerResponse;
import com.mmall.pojo.User;
import com.mmall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver;

import javax.servlet.http.HttpSession;

/**
 * Created by root on 18-4-7.
 */
public class UserHelper {

    public static ServerResponse validAdmin (HttpSession session){
        User user = (User)session.getAttribute(Const.CURRENT_USER);
        if (user == null){
            return ServerResponse.createByError(ResponseCode.NEED_LOGIN.getCode(), "login first.");
        }

        if (!(user != null && Const.Role.ROLE_ADMIN == user.getRole())){
            return ServerResponse.createByError("you are not an admin role,don't have the privileges");
        }
        return ServerResponse.createBySuccess();
    }
}
